import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'portfolioRiskM',
  state: {},
  effects: {
    // 获取风险分层拆解接口
    *getDecompositionMap({ payload, callback }, { call, put }) {
      const response = yield call(api.portfolioRisk.getDecompositionMap, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '获取风险分层拆解图失败！');
      }
    },
    // 获取超额风险趋势图
    *getRiskTrend({ payload, callback }, { call, put }) {
      const response = yield call(api.portfolioRisk.getRiskTrend, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '获取超额风险趋势图失败！');
      }
    },
    // 查询风格因子和行业因子表格
    *getFactor({ payload, callback }, { call, put }) {
      const response = yield call(api.portfolioRisk.getFactor, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '获取因子风险贡献失败！');
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
